<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(logs) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
$handle = fopen("./json", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 4096);
    $array[] = $buffer;
    $arr = json_decode($buffer, true);
    
    $id = $arr["gamename"];
    $id2 = $arr["createdate"];
    $id3 = $arr["data"]["OnlineFightCount"];
    $id4 = $arr["data"]["Cents4999"];
    $id5 = $arr["data"]["Cents999"];
    $id6 = $arr["data"]["Cents9999"];
    $id7 = $arr["data"]["AllCents"];
    $id8 = $arr["data"]["Cents099"];
    $id9 = $arr["data"]["gameTime"];
    $id10 = $arr["data"]["stageMax"];
    $id11 = $arr["data"]["days"];
    $id12 = $arr["data"]["NormalStageFightCount"];
    $id13 = $arr["data"]["Cents1999"];
    $id14 = $arr["data"]["Cents499"];
    $id15 = $arr["data"]["OnlineFightWinCount"];
    $id16 = $arr["data"]["NowtCrystals"];
    $id17 = $arr["data"]["BossStageFightCount"];
    $id18 = $arr["data"]["AlltCrystals"];
    $id19 = $arr["data"]["versionNum"];
    $id20 = $arr["deviceid"];

    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
        $gamename = $id;
        $createdate = $id2;
        $OnlineFightCount = $id3;
        $Cents4999 = $id4;
        $Cents999 = $id5;
        $Cents9999 = $id6;
        $AllCents = $id7;
        $Cents099 = $id8;
        $gameTime = $id9;
        $stageMax = $id10;
        $days = $id11;
        $NormalStageFightCount = $id12;
        $Cents1999 = $id13;
        $Cents499 = $id14;
        $OnlineFightWinCount = $id15;
        $NowtCrystals = $id16;
        $BossStageFightCount = $id17;
        $AlltCrystals = $id18;
        $versionNum = $id19;
        $deviceid = $id20;
        mysql_query("INSERT INTO logs (gamename, createdate, OnlineFightCount, Cents4999, Cents999, Cents9999, AllCents, Cents099, gameTime, stageMax, days, NormalStageFightCount,Cents1999,Cents499,OnlineFightWinCount,NowtCrystals,BossStageFightCount,AlltCrystals,versionNum,deviceid ) VALUES('$gamename', '$createdate', '$OnlineFightCount', '$Cents4999', '$Cents999', '$Cents9999', '$AllCents', '$Cents099','$gameTime','$stageMax','$days','$NormalStageFightCount','$Cents1999','$Cents499','$OnlineFightWinCount','$NowtCrystals','$BossStageFightCount','$AlltCrystals','$versionNum','$deviceid')") or die(mysql_error());
    }
}
fclose($handle);
echo "Import successful";
?>